package com.hk.dao.manage.sys.authority.enums;

import com.hk.commons.eunms.Enums;

public enum ResourceTypeEnum implements Enums<Integer> {
    CATALOG(1,"目录"),
    MENU(2,"菜单"),
    BUTTON(3,"按钮");

    private Integer code;
    private String desc;

    private ResourceTypeEnum(Integer code, String desc){
        this.code = code;
        this.desc = desc;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getDesc() {
        return desc;
    }

    @Override
    public String getDesc(Object... objs) {
        return desc;
    }

    // 通过value获取对应的枚举对象
    public static ResourceTypeEnum getEnums(String value) {
        for (ResourceTypeEnum code : ResourceTypeEnum.values()) {
            if (code.getCode().equals(value)) {
                return code;
            }
        }
        return null;
    }

    /**
     * 根据 code 获得 desc
     * @param code
     * @return
     */
    public static String getValueByKey(Integer code) {
        ResourceTypeEnum[] enums = ResourceTypeEnum.values();
        for (int i = 0; i < enums.length; i++) {
            if (enums[i].getCode().equals(code)) {
                return enums[i].getDesc();
            }
        }
        return "";
    }

    public static Integer getKeyByValue(String code) {
        ResourceTypeEnum[] enums = ResourceTypeEnum.values();
        for (int i = 0; i < enums.length; i++) {
            if (enums[i].getDesc().equals(code)) {
                return enums[i].getCode();
            }
        }
        return null;
    }
}
